<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
            <a-button icon="plus" type="primary" @click="add">{{$ti18('rxList.newBtn','新建')}}</a-button>
            <a-dropdown v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
              <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}} <a-icon type="down" /> </a-button>
              <a-menu slot="overlay">
                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0" @click="editOne"><a-icon type="edit"  />{{$ti18('rxList.editBtn','编辑')}}</a-menu-item>
                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0" @click="delByIds(selectedRowKeys)"><a-icon type="delete" />{{$ti18('rxList.delBtn','删除')}}</a-menu-item>
              </a-menu>
            </a-dropdown>
          </div>
          <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
        </div>
        <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
          <a-form layout="vertical">
                <a-form-item :label="i18n('form.name','名称')">
                    <a-input :placeholder="i18n('form.name','名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                </a-form-item>
                <a-form-item :label="i18n('form.key','标识')">
                    <a-input :placeholder="i18n('form.key','请输入标识','input')" v-model="queryParam.Q_KEY__S_LK"/>
                </a-form-item>
          </a-form>
        </div>
        <rx-grid
                ref="table"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-form/form/codegen/formCodegenFileTemplate/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                @selectChange="onSelectChange"
        >
          <span slot="enabled" slot-scope="{ text,record }">
            <a-tag :color="enabledMap[text].color">
                <span>{{enabledMap[text].text}}</span>
              </a-tag>
          </span>
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span  @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
            <span  @click="design(record)">{{i18n("list.design","设计")}}</span>
            <span  @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import FormCodegenFileTemplateApi from '@/api/form/codegen/formCodegenFileTemplate'
  import FormCodegenFileTemplateEdit from './FormCodegenFileTemplateEdit'
  import FormCodegenFilePathConfig from "./FormCodegenFilePathConfig";
  import {BaseList, RxFit, RxGrid, Util} from "@lowcode/jpaas-common-lib";
  export default {
    name: 'FormCodegenFileTemplateList',
    mixins: [BaseList],
    components: {
      RxFit
    },
    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 100,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('form.name','名称'), dataIndex: 'name', width: 100},
          {title: this.i18n('form.key','标识'), dataIndex: 'key', width: 100},
          {title: this.i18n('form.enabled','是否启用'), dataIndex: 'enabled', width: 100, scopedSlots: {customRender: 'enabled'}},
          {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component:FormCodegenFileTemplateEdit,
        comment: this.i18n('list.comment','空项目代码文件模板表'),
        widthHeight:['600px','300px'],
        fitSearch:false,
        enabledMap: {
            'YES': {color: 'green', text: this.$comi18('rxDialog.statusYse', '启用')},
            'NO': {color: 'blue', text: this.$comi18('rxDialog.statusNo', '禁用')}
        },
      }
    },
    methods:{
      i18n(name,text,key){
        return this.$ti18(name,text,"formCodegenFileTemplate",key);
      },
      delById(ids){
        return FormCodegenFileTemplateApi.del({ ids: ids.join(',') });
      },
      getListByParams(parameter){
        return FormCodegenFileTemplateApi.query(parameter)
      },
      design(record){
        var config = {
          curVm: this,
          component: FormCodegenFilePathConfig,
          title: this.i18n('list.title','模板文件设计'),
          max: true,
          data: {
            templateId: record.id
          }
        };
        Util.open(config, function (action) {
        })
      }

    }
  }
</script>
<style scoped>
  .table-operator {
    padding:4px;
  }
  .table-operator button {
    margin:2px;
  }
</style>

